<?php
if (!class_exists("go_sql")){
	include("/var/www/html/new/conf/le.je");
	$le=new go_sql();
	$le->connect();
}
include_once '/var/www/html/new/d/meituan/MT.class.php';
$meituan = new Meituan();

$txt=json_encode($_REQUEST);
$changeurl = 'http://lvyou.meituan.com/rhone/lv/deal/change/notice';
// $meituan->logfile($txt,"changenotice");
$ids = $_REQUEST['ids'];
$status =$_REQUEST['status']; // 0,下架 1,上架 2,修改
$signkey = $_REQUEST['signkey'];
$supplierIdentity = $_REQUEST['supplierIdentity'];
if($ids){	
	$partnerId = $supplierIdentity;
	$signkeys = explode("|",$signkey);
	$clientID = $signkeys[0];
	$clientsecret = $signkeys[1];
	
	date_default_timezone_set('GMT');
	$date = date('D, d M Y H:i:s e', time());
	date_default_timezone_set('PRC');
	$authorization = buildSign('POST',$date,$clientID,$clientsecret);

	$header = array(
		"Content-Type: application/json; charset=utf-8",
		"Date:" . $date,
		"PartnerId:" . $partnerId,
		"Authorization:" . $authorization,
	);
	$body[] = array(
		'partnerDealId'=>$ids,
		'status'=>$status
	);
	$response = array(
		'code'=>200,
		'describe'=>"产品变化通知",
		'partnerId'=>$partnerId,
		'body'=>$body				
	);	
	$data = json_encode($response);
	$a = mt_notice_post($data,$header,$changeurl);
	echo $a;
	$meituan->logfile($txt."|".$a,"changenotice");
}
function mt_notice_post($data,$header,$url){ //美团提供的消费地址
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_POST, 1); 
	curl_setopt($ch, CURLOPT_HEADER, 0); 
	curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_URL,$url); 
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
	$result=  curl_exec($ch); 
	curl_close($ch);
	return $result;
}

function buildSign($method,$date,$clientID,$clientsecret){
	$string_to_sign = $method . ' ' . '/rhone/lv/deal/change/notice' . "\n" . $date;
	$signature = base64_encode(hash_hmac('sha1', $string_to_sign, $clientsecret, true));
	$authorization = 'MWS ' . $clientID . ':' . $signature;
	return $authorization;	
}
?>